var Book = require('mongoose').model('book')
module.exports = {
  add: async (ctx, next) => {
    try {
      var param = ctx.request.body;
      var book = await Book.create(param)
      console.log('添加成功', book)
      ctx.status = 200;
      ctx.body = book
    } catch (error) {
      console.log(error)
    }
  },
  update: async (ctx, next) => {
    var param = ctx.request.body
    const result = await User.findByIdAndUpdate({
      _id: param._id
    }, {
      $set: param
    })
    ctx.status = 200;
    ctx.body = result
  },
  delete: async (param) => {
    param ? param : {}
    return await User.remove(param)
  },
  query: async (ctx, next) => {
    var param = ctx.query
    param ? param : {}
    return await User.find(param)
  }
}